package org.smth.search;

import com.google.inject.Guice;
import com.google.inject.Injector;

import org.smth.search.config.FetcherConfig;
import org.smth.search.fetcher.FetcherManager;

public class Starter {

	private Injector injector;

	private Starter() {
		injector = Guice.createInjector(new SearcherModule());
	}

	private static class StarterHolder {
		private static Starter instance = new Starter();
	}

	public static Starter getInstance() {
		return StarterHolder.instance;
	}

	public Injector getInjector() {
		return injector;
	}

	public static void main(String[] args) throws Exception {
		Injector injector = getInstance().getInjector();
		FetcherManager manager = injector.getInstance(FetcherManager.class);
		FetcherConfig config = injector.getInstance(FetcherConfig.class);
		manager.setThreadNum(config.getThreadsNum());
		manager.setInjector(injector);
		manager.startAllNoStop(20000);
		if (System.in.read() > 0) {
			manager.stopAll();
		}
	}

}
